﻿
using MediatR;
using Microsoft.AspNetCore.Components.Forms;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command;
namespace U.B.WriteApi.CommandHander
{
    public class DelRoleCommandHander : IRequestHandler<DelRoleCommand, ApiResult<object>>
    {
        public readonly IRepistory<Role>  _roleRepository;
        public DelRoleCommandHander(IRepistory<Role> roleRepository)
        {
            _roleRepository = roleRepository;
        }
        public Task<ApiResult<object>> Handle(DelRoleCommand request, CancellationToken cancellationToken)
        {
           ApiResult<object> apiResult = new ApiResult<object>();
            var result = _roleRepository.GetAll().Where(x => x.RoleId == request.RoleId).FirstOrDefault();
            _roleRepository.Delete(result);
            apiResult.code = Renum.删除成功;
            apiResult.Message=Renum.删除成功.ToString();
            return Task.FromResult(apiResult);
        }
    }
}
